<template>
  <el-dialog
    title="新增部门"
    :visible="addVisible"
    width="30%"
    @close="closeAddDialog"
  >
    <el-form label-width="120px" :model="from" :rules="rules" ref="deptForm">
      <el-form-item label="部门名称" prop="name">
        <el-input v-model="from.name" style="width:80%" placeholder="1-50个字符" />
      </el-form-item>
      <el-form-item label="部门编码" prop="code">
        <el-input v-model="from.code" style="width:80%" placeholder="1-50个字符" />
      </el-form-item>
      <el-form-item label="部门负责人" prop="manager">
        <el-select  v-model="from.manager" style="width:80%" placeholder="请选择" />
      </el-form-item>
      <el-form-item label="部门介绍" prop="introduce">
        <el-input v-model="from.introduce" style="width:80%" placeholder="1-300个字符" type="textarea"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="primary" size="small">确定</el-button>
      <el-button size="small">取消</el-button>
    </template>
  </el-dialog>
</template>

<script>
export default {
  props: {
    addVisible: {
      type: Boolean
    }
  },
  data() {
    return {
      from:{
        name:'',
        code:'',
        manager:'',
        introduce:''
      },
      rules:{
            name: [
              { required: true, message: '部门名称不能为空', trigger: ['blur', 'change'] },
              { min: 1, max: 50, message: '部门名称要求1-50个字符', trigger: ['blur', 'change'] }
            ],            
            code: [
              { required: true, message: '部门编码不能为空', trigger: ['blur', 'change'] },
              { min: 1, max: 50, message: '部门编码要求1-50个字符', trigger: ['blur', 'change'] }
            ],
            manager: [
              { required: true, message: '部门负责人不能为空', trigger: ['blur', 'change'] }
            ],
            introduce: [
              { required: true, message: '部门介绍不能为空', trigger: ['blur', 'change'] },
              { min: 1, max: 300, message: '部门介绍要求1-300个字符', trigger: ['blur', 'change']}
            ]
      }
    }
  },
  methods: {
    closeAddDialog() {
      this.$emit('close-dialog')
    }
  }
}
</script>